package com.cq.hd.member.controller;

import com.alibaba.fastjson.JSONObject;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbAgentEnterApplyApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbAgentEnterApplyService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 经纪人入驻申请记录表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2024-01-18
 */
@RestController
public class TbAgentEnterApplyController implements TbAgentEnterApplyApi {

    @Autowired
    private TbAgentEnterApplyService agentEnterApplyService;

    @ApiOperation(value = "经纪人入驻预申请（供用户点击入驻申请链接调用）")
    @ApiResponse(response = PreAgentApplyMerchantVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<PreAgentApplyMerchantVo> preApply(@RequestBody PreAgentEnterApplyDto preAgentApplyMerchantDto) {
        return ResultGenerator.success(agentEnterApplyService.preApply(preAgentApplyMerchantDto));
    }

    @ApiOperation(value = "经纪人绑定商家（经纪人开户）")
    @Override
    public Result<Boolean> bind(@RequestBody BusinessAgentBindDto businessAgentBindDto) {
        return ResultGenerator.success(agentEnterApplyService.bind(businessAgentBindDto));
    }

    @ApiOperation(value = "经纪人开户")
    @Override
    public Result<AgentEnterApplyVo> bindHf(AgentBindHfDto agentBindHfDto) {
        return ResultGenerator.success(agentEnterApplyService.bindHf(agentBindHfDto));
    }

    @ApiOperation(value = "返回已签约的银行卡列表")
    @Override
    public Result<List<AgentBankCardVo>> listBank(Long userId) {
        return ResultGenerator.success(agentEnterApplyService.listBank(userId));
    }

    @ApiOperation(value = "经纪人入驻，绑定银行卡，并做签约，返回签约地址")
    @Override
    public Result<AgentEnterApplyVo> enterApply(@RequestBody AgentEnterApplyDto agentEnterApplyDto) {
        return ResultGenerator.success(agentEnterApplyService.enterApply(agentEnterApplyDto));
    }

    // 是否存在入驻失败/签约失败的入驻数据,倒序查询第一条的入驻记录是否是入驻失败/签约失败,如果是,则需要重新提交
    @ApiOperation(value = "获取入驻状态")
    @Override
    public Result<AgentEnterApplyStateVo> getEnterInfoState(Long userId) {
        return ResultGenerator.success(agentEnterApplyService.getEnterInfoState(userId));
    }

    @ApiOperation(value = "用户业务入驻异步通知回调")
    @Override
    public Result<Boolean> agentUserEntAuditCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(agentEnterApplyService.agentUserEntAuditCallback(dataObj));
    }

    @ApiOperation(value = "用户签约结果异步通知回调")
    @Override
    public Result<Boolean> agentUserSignCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(agentEnterApplyService.agentUserSignCallback(dataObj));
    }

    @ApiOperation(value = "根据条件获取入驻数据")
    @Override
    public Result<List<AgentEnterApplyDetailVo>> listByDto(AgentEnterApplyDetailDto agentEnterApplyDetailDto) {
        return ResultGenerator.success(agentEnterApplyService.listByDto(agentEnterApplyDetailDto));
    }

    @ApiOperation(value = "修改银行卡")
    @Override
    public Result<Boolean> updateBankInfo(@RequestBody AgentUpdateBankInfoDto agentUpdateBankInfoDto) {
        return ResultGenerator.success(agentEnterApplyService.updateBankInfo(agentUpdateBankInfoDto));
    }
}
